<?php
// +----------------------------------------------------------------------
// | Created by Sublime: [ Conqweal ]
// +----------------------------------------------------------------------
// | Copyright (c) 2021~20223[chenjia] All rights reserved.
// +----------------------------------------------------------------------
// | SiteUrl: http://www.99dn.cn
// +----------------------------------------------------------------------
// | Author: Conqweal <150672834@qq.com>
// +----------------------------------------------------------------------
// | Date: 2021/12/22 0026
// +----------------------------------------------------------------------
// | Description:后台基础控制器
// +----------------------------------------------------------------------
namespace app;

use support\View;
use Webman\Event\Event;

class BackendController
{
    protected $lang_id;
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function __construct()
    {
        $default_lang = 'zh_CN';
        locale($default_lang);
        $this->lang_id = getLangs($default_lang);
        $data          = [
            'name' => 'syslog',
            'age'  => 2,
        ];
        Event::emit('syslog.handle', $data);

        View::assign('cdn_host', 'http://localhost:8787');

    }

    public function success($msg, $url = '')
    {
        $is_ajax = request()->isAjax();
        $result  = [
            'code'   => 0,
            'msg'    => $msg,

            'url'    => $url,
            'wait'   => 3,
            'status' => 1,
        ];
        if ($is_ajax) {
            return json($result);
        } else {
            return view("public/dispatch", $result);
        }

    }

    public function error($msg, $url = '')
    {
        $is_ajax = request()->isAjax();
        $result  = [
            'code'   => 0,
            'msg'    => $msg,

            'url'    => $url,
            'wait'   => 3,
            'status' => -1,
        ];
        if ($is_ajax) {
            return json($result);
        } else {
            return view("public/dispatch", $result);
        }
    }

}
